package com.fms.constant;

import lombok.AllArgsConstructor;
import org.springframework.security.core.GrantedAuthority;

import java.util.Optional;

@AllArgsConstructor
public enum Role implements GrantedAuthority {
    ADMIN("ROLE_管理员"),
    GENERAL_MANAGER("ROLE_总经理"),
    MANAGER("ROLE_经理"),
    DESIGNER("ROLE_设计师"),
    KAILIAO("ROLE_开料师"),
    XIALIAO("ROLE_下料师"),
    INSTALLER("ROLE_安装师"),
    CLERK("ROLE_文员"),
    MACHINIST("ROLE_机械师"),
    CHAIDAN("ROLE_拆单师"),
    PURCHASE("ROLE_采购员"),
    FINANCE("ROLE_财务员");



    private final String authority;


    public static Optional<Role> of(String authority) {
        for (Role role : Role.values()) {
            if (role.getAuthority().equals(authority)) {
                return Optional.of(role);
            }
        }
        return Optional.empty();
    }


    @Override
    public String getAuthority() {
        return authority;
    }

    @Override
    public String toString() {
        return authority;
    }

}